from __future__ import annotations

from dataclasses import dataclass
from math import pi


@dataclass
class GroundWireSizing:
    min_area_mm2: float
    note: str


def size_ground_wire(short_circuit_kA: float, duration_s: float, material_const_A: float = 115.0) -> GroundWireSizing:
    """接地线截面：S = I·√t / k（k按材料常数）。"""

    S = (short_circuit_kA * 1000.0) * (duration_s ** 0.5) / material_const_A
    return GroundWireSizing(min_area_mm2=S, note="按热稳定校核，需温升限制复核")


@dataclass
class ReelParams:
    cable_length_m: float
    reel_diameter_m: float
    reel_width_m: float
    weight_t: float
    note: str


def estimate_reel_parameters(unit_weight_kN_m: float, length_m: float, min_bend_diameter_m: float, packing_factor: float = 0.85) -> ReelParams:
    """线缆盘参数估算：以最小弯曲直径为芯，按填充系数估盘径和重量。"""

    D = max(min_bend_diameter_m, 1.6)
    width = max(1.2, length_m / 500.0)
    weight_t = unit_weight_kN_m * length_m / 9.81 / 1000.0
    return ReelParams(cable_length_m=length_m, reel_diameter_m=D / packing_factor, reel_width_m=width, weight_t=weight_t, note="经验估算，需厂家参数")


